<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
</head>
<body>
<form id="signinForm">
    <div>
        <label>用户名
            <input type="text" name="name">
        </label>
    </div>
    <div>
        <label>密码
            <input type="password" name="password">
        </label>
    </div>
    <div>
        <button type="submit">登录</button>
    </div>
</form>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
    const $form = $('#signinForm')
    $form.on('submit',(e)=>{
        e.preventDefault() //阻止默认事件
        const name = $form.find('input[name=name]').val();
        const password = $form.find('input[name=password]').val();
        $.ajax({
            method:'POST',
            url:'/signin',
            contentType:'text/json;charset=UTF-8',
            // data: JSON.stringify({name:name,password:password})
            data: JSON.stringify({name,password})
        }).then(()=>{
            alert("登录成功")
            location.href = '/home.html'
        },()=>{})
    })
</script>
</body>
</html>